<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item :label="$t('employing_company')" prop="employerId">
        <employerSelect v-model="queryParams.employerId" @change="employerChange"></employerSelect>
      </el-form-item>
      <!-- <el-form-item :label="$t('employee_name')" prop="employeeId">
        <el-select v-model="queryParams.employeeId" filterable
          :placeholder="$t('please_enter', { name: $t('employee_name') })">
          <el-option v-for="(item, index) of employeeList" :label="item.employeeName" :value="item.id"
            :key="index"></el-option>
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item :label="$t('year_month')" prop="month">
        <el-date-picker v-model="queryParams.month" type="month"
          :placeholder="$t('please_select', { name: $t('year_month') })" value-format="yyyy-MM" size="small">
        </el-date-picker>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">{{ $t('search') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('reset') }}</el-button>
      </el-form-item>
    </el-form>
    <!-- 
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['checkWork:checkWorkCount:export']"
          >{{$t('export')}}</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row> -->
    <performanceTable :loading="loading" :tableData="scheduleList">
      <el-table-column :label="$t('action')" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['performance:performance:edit']">{{ $t("modify_evaluator") }}</el-button>
          <el-button size="mini" type="text" icon="el-icon-s-promotion" @click="handleSend(scope.row)"
            v-hasPermi="['performance:performance:push']">{{ $t("distribution_performance") }}</el-button>
        </template>
      </el-table-column>
    </performanceTable>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList"
      :page-sizes="[10,20,30,50,100, 200]"
      />
    <AddOrUpdata ref="performanceDetail" @handleSuccess="handleSuccess"></AddOrUpdata>
  </div>
</template>

<script>
import { pageList, distribution } from "@/api/custom/employerList";
import performanceTable from "@/views/custom/performance/performanceTable.vue";
import AddOrUpdata from "@/views/custom/performance/AddOrUpdata.vue";
import { listAttendance, delAttendance } from "@/api/checkWork/checkWorkCount";
import { pageListByEmployer } from "@/api/custom/employeeList";
import employerSelect from "@/views/components/custom/employerSelect.vue";

export default {
  name: "Schedule",
  components: {
    performanceTable,
    AddOrUpdata,
    employerSelect,
    pageListByEmployer
  },
  data() {
    return {
      showSearch: true,
      // 总条数
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      loading: false,

      needInfo: {},
      scheduleList: [],

      annualLeave: [
        {
          lengthService: null,
          vacation: null,
        },
      ],
      employeeList:[],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    employerChange() {
      this.queryParams.employeeId = null;
      this.pageListByEmployer();
    },
    pageListByEmployer() {
      pageListByEmployer({
        employerId: this.queryParams.employerId,
      }).then((res) => {
        this.employeeList = res.data.records;
      });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 查询假期列表 */
    getList() {
      this.loading = true;
      pageList(this.queryParams).then((response) => {
        this.scheduleList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    handleSuccess() {
      this.getList();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      let detailParams = {
        item: row,
        title: this.$t("modify"),
      };
      this.$refs.performanceDetail.showDateschedule(detailParams);
    },
    handleSend(row) {
      distribution(row.performanceEmployerConfigId).then((res) => {
        this.$message.success(res.msg);
        this.getList();
      });
    },
  },
};
</script>
